#include <stdio.h>
#include <stdlib.h>

struct vector {
	int *data;
	size_t length;
	size_t length_max;
};

void
vector_init_(struct vector *v)
{
	v->data = calloc((size_t) 4, sizeof *v->data);
	v->length = 0UL;
	v->length_max = 4UL;
}

void
vector_add(struct vector *v, int a)
{
	if (v->length + 1UL > v->length_max)
		v->data = realloc(v->data,
				(sizeof *v->data) * (v->length_max *= 2));
	v->data[v->length++] = a;
}

void
vector_kill_(struct vector *v)
{
	free(v->data);
	v->length = v->length_max = 0UL;
}

int
main(int argc, char **argv)
{
	struct vector *db;
	int i = 0, n;
	int op, idx, val, elem;

	scanf("%d", &n);
	db = malloc((size_t) n * sizeof *db);
	for (i = 0; i < n; i++)
		vector_init_(db + i);

	while (1) {
		scanf("%d", &op);
		if (op == 1) {
			scanf("%d%d", &idx, &val);
			--idx;

			if (idx < 0 || idx >= n) {
				fputs("-1\n", stdout);
				continue;
			}

			vector_add(db + idx, val);
		} else if (op == 2) {
			scanf("%d%d", &idx, &elem);
			--idx,elem--;

			if (idx < 0 || idx >= n) {
				fputs("-1\n", stdout);
				continue;
			}
			if (elem < 0 || elem >= db[idx].length) {
				fputs("-2\n", stdout);
				continue;
			}

			printf("%d\n", db[idx].data[elem]);
		} else if (op == 3) {
			break;
		}
	}

	for (i = 0; i < n; i++) vector_kill_(db + i);
	free(db);

	return 0;
}
